package cn.tedu.mall.front.service.impl;

import cn.tedu.mall.common.exception.CoolSharkServiceException;
import cn.tedu.mall.common.restful.ResponseCode;
import cn.tedu.mall.front.mappers.FrontSpuAttributeMapper;
import cn.tedu.mall.front.service.IFrontAttributeService;
import cn.tedu.mall.pojo.front.vo.SelectAttributeVO;
import cn.tedu.mall.pojo.product.vo.AttributeStandardVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FrontSpuAttributeServiceImpl implements IFrontAttributeService {

    private final FrontSpuAttributeMapper frontSpuAttributeMapper;

    @Autowired
    public FrontSpuAttributeServiceImpl(FrontSpuAttributeMapper frontSpuAttributeMapper) {
        this.frontSpuAttributeMapper = frontSpuAttributeMapper;
    }

    @Override
    public SelectAttributeVO getAllRelatedAttributes(Long categoryId) {
        return null;
    }

    @Override
    public List<AttributeStandardVO> getSpuAttributesBySpuId(Long id) {
        List<AttributeStandardVO> attributeStandardVOList = frontSpuAttributeMapper.getAllAttributesBySpuId(id);
        if (attributeStandardVOList == null) {
            throw new CoolSharkServiceException(ResponseCode.NOT_FOUND, "此SpuId下没有对应的属性！");
        }
        return attributeStandardVOList;
    }
}
